#define TIME_TO_KEG 500000 //  
#define TIME_TO_LINE 500000 //  
//  I2C .
#include <Wire.h>
//   .
#include IRremote.h
//   .
#include motor.h
//   .
#include gyro_acsel.h
//   .
#include memcolor.h
void yellow_8(float aaa);
void red_8(float aaa);
//   IR-.
int RECV_PIN = A1;
//  IR-.
IRrecv irrecv(RECV_PIN);
//   IR-.
decode_results results;
//========================================
void setup()
{
Serial.begin(9600);
// .
giroscop_setup();
apds9960_setup();
//     () Arduino.
//      .
setup_motor_system(3, 4, 11, 7, 8, 10);
_stop(); // .
67
//  IR-.
//    .
delay(1000);
Calc_CompensatorZ(3000);
irrecv.enableIRIn();
Serial.print( Start );
Ang_ = 0;
setspeed(255, 255);
}
//=====================================
//  .
void loop()
{
// float Ang2 = Ang_;
while (1)
{
// delay(30000);
if (irrecv.decode(&results))
{
// Serial.println(results.value, HEX);
switch (results.value) {
// 1 
case 0xC101E57B:
yellow_8(0);
break;
// 2 
case 0x97483BFB:
red_8(0);
break;
// 3  
case 0xF0C41643:
foto_yellow();
break;
// 4   
case 0x9716BE3F:
yellow_8(22.5);
break;
// 5   
case 0x3D9AE3F7:
red_8(22.5);
break;
// 6  
case 0x6182021B:
foto_red();
break;
//  10 
case 0x511DBB:
break;
//  10 
case 0xA3C8EDDB:
break;
case 0x32C6FDF7: // *
number_test_yellow = 0;
number_test_red = 0;
Serial.println(number_test_yellow = 0; number_test_red = 0;);
break;
case 0x1BC0157B: // 0
write_color_data_eeprom();
break;
}
68
irrecv.resume();
}
// delay(40);
time_gyro(0.5);
apds9960_read();
}
}
//=====================================
void yellow_8(float aaa)
{
float x;
x = aaa;
while (x > 2)
{
Angle(x / 2);
x = aaa - Ang_;
}
time_gyro(100);
Ang_ = 0;
for (int i = 0; i < 8; i++)
{
forward_t(TIME_TO_KEG);
time_gyro(500);
if (test_yellow())
{
//Serial.println( Yellow );
forward_t(TIME_TO_LINE);
time_gyro(500);
backward_t(TIME_TO_LINE);
}
backward_t(TIME_TO_KEG);
time_gyro(500);
x = float((i + 1) * 45) - Ang_;
while (x > 2)
{
Angle(x / 2);
x = float((i + 1) * 45) - Ang_;
}
time_gyro(500);
}
}
//=====================================
void red_8(float aaa)
{
float x;
x = aaa;
while (x > 2)
{
Angle(x / 2);
x = aaa - Ang_;
}
time_gyro(100);
Ang_ = 0;
for (int i = 0; i < 8; i++)
{
forward_t(TIME_TO_KEG);
time_gyro(500);
if (test_red())
{
// Serial.println( red );
69
forward_t(TIME_TO_LINE);
time_gyro(500);
backward_t(TIME_TO_LINE);
}
backward_t(TIME_TO_KEG);
time_gyro(500);
x = float((i + 1) * 45) - Ang_;
while (x > 2)
{
Angle(x / 2);
x = float((i + 1) * 45) - Ang_;
}
time_gyro(500);
}
}